<template id="edit_address">
	<div class="edit_address">

		<!--头部-->
		<div class="about_header">

			<div class="about_title">
				<router-link to="/select_address"><img src="../../assets/images/class/jiantou_03.png" /></router-link>

				<p>修改地址</p>
				<div class="about_select">
					<div class="about_ing" @click.stop="delAll">删除</div>
				</div>

			</div>
		</div>
		<!--头部结束-->

		<!--修改个人信息-->
		<div class="edit_means">

			<div class="select_date">
				<div class="select_ipt">
					<img src="../../assets/images/new_address/new_07.png" />
					<input type="text" name="" id="" value="" v-model="username" maxlength="10" @change="nameChange($event)" />
					<img src="../../assets/images/new_address/new_22.png" @click.stop="nameMost" />

				</div>
			</div>

			<div class="select_date">
				<div class="select_ipt">
					<img src="../../assets/images/new_address/new_11.png" />
					<input type="number" name="" id="" v-model="phone"  oninput="if(value.length>1)value=value.slice(0,2)" @change="phhotoChange($event)" />
					<img src="../../assets/images/new_address/new_22.png" @click.stop="phoneMost" />

				</div>
			</div>

			<div class="select_data">
				<div class="select_ipt">
					<img src="../../assets/images/new_address/new_15.png" />
					<router-link   :to="{path: '/search_address',query:
						{
							'username':this.username,
							'phone':this.phone,
							'detailAddr':this.detailAddr,
							'about_coach':this.$route.query.about_coach,
							'coachid': this.$route.query.coachid,
							'user':this.user,
							'area':this.area,
							'street':this.street,
							'edifice':this.edifice,
							 'lng': this.lng,
							 'lat': this.lat,
							 'city':this.$route.query.city,
							 'id': this.$route.query.id
						}}" style="width:100%;display: flex;"><span style="display: flex;margin-left: 10px;width:100%;border: none;
    background: none;
    outline: none;
    font-size: 18px;">{{address_detail}}</span>
					<!-- <input type="text" name="" id="" v-model="city" style="margin-left:0;width:0;" @change="cityChange($event)" /> -->
					</router-link>

				</div>
			</div>
			<div class="select_date">
				<div class="select_ipt">
					<img src="../../assets/images/new_address/new_19.png" />
					<input type="text" name="" id="" v-model="detailAddr" maxlength="30"  @change="detailAddrChange($event)" />
					<img src="../../assets/images/new_address/new_22.png" @click.stop="detailAddrMost" />

				</div>
			</div>

			<!--<div class="select_datk">
				<div class="select_ipt">
					<img src="../../assets/images/new_address/new_27.png" />
					<span class="bug"  :class="[idx == index?'active':'']" @click="isActive(index)" v-for="(item,index) in todo" :key="index">{{item.family}}</span>

				</div>
			</div>-->

		</div>

		<!--提交修改-->
		<div class="edit_submit" @click.stop="deitDetail">
			<button>保存</button>
		</div>
		<!--提交修改结束-->

	</div>
</template>

<script>
	export default {
		data() {
			return {
				index: '0',
				user: this.$route.query.user,
				phone: '',
				username: '',
				city: '',
				area: this.$route.query.area,
				street: this.$route.query.street,
				edifice: this.$route.query.edifice,
				detailAddr:  this.$route.query.detailAddr,
				lng: '',
				lat: '',
				id: this.$route.query.id,
				address_detail: '',
			}
		},
		created() {
			this.id = this.$route.query.id;
			this.username = this.$route.query.username;
			this.phone = this.$route.query.phone;
			this.city = this.$route.query.city;
			// this.detailAddr = this.$route.query.detail_addr;
			this.area = this.$route.query.area;
			this.street = this.$route.query.street;
			this.edifice = this.$route.query.edifice;
			this.detailAddr = this.$route.query.detailAddr;
			this.lng = this.$route.query.lng;
			this.lat = this.$route.query.lat;
			 var baidu=decodeURI(this.$route.query.baiduapi)
		        if (baidu == 'undefined') {
		        	this.address_detail=this.city+this.area+this.street+this.edifice+this.detailAddr
		        }else{
		        	this.address_detail=baidu
		        }



			// this.address_detail = decodeURI(this.$route.query.baiduapi);
			console.log(baidu)
			// this.address_detail = decodeURI(this.$route.query.baiduapi);
			// console.log(this.detailAddr)
		},
		methods: {
			HeightL: function(index) {
				this.index = index
			},
			nameMost() {
				this.username = "";
			},
			nameChange(e) {
				this.username = e.target.value;
				console.log(e.target.value)
			},
			phoneMost() {
				this.phone = "";
			},
			phhotoChange(e) {
				this.phone = e.target.value;
				console.log(e.target.value)
			},
			cityChange(e) {
				this.city = e.target.value;
			},
			detailAddrChange(e) {
				this.detailAddr = e.target.value;
			},
			detailAddrMost() {
				this.detailAddr = "";
			},
			deitDetail() {
				//let SESSION_ID = JSON.parse(window.sessionStorage.getItem('SESSION_ID'));
				 var SESSION_ID=JSON.parse(window.localStorage.getItem('sessiond'))
				let _this = this
				let username = _this.username; //姓名
				let phone = _this.phone; //手机号
				let city = _this.city;
				let area = _this.area;
				let street = _this.street;
				let edifice = _this.edifice;
				let detailAddr = _this.detailAddr
				let obj = {
					//请求的参数
					//coachid: 88891,
					// user: '',
					city:this.$route.query.city,
					user: this.$route.query.user,
					// city: this.$route.query.city,
					// area: '',
					area: this.$route.query.area,
					// street: '',
					street: this.$route.query.street,
					// edifice: '',
					edifice: this.$route.query.edifice,
					detailAddr: this.detailAddr,
					lng:this.$route.query.lng,
                	lat:this.$route.query.lat,
					addressid: this.id,
					code: 1,
					userid: SESSION_ID.user.id,
					username,
					phone,
				};
				if(_this.phone == "") {

				} else {

				}
				console.log(obj)
				let qs = require('qs');
				this.$axios.post("/Scanning/user/updateAddress ", qs.stringify(obj), {
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}
					//重写headers 请求头  qs.stringify(json对象) 把对象转化为字符串
				}).then((response) => {
					console.log(response)
					if(response.data.code == -2) {
						mui.alert("信息填写不完整,请重新添加")
					} else if(response.data.code == 1) {
						mui.alert("修改成功")
						this.$router.push({
							path: '/select_address',
							query: {}
            
						})
					}else if(response.data.code == -1){
						mui.alert('修改失败')
					}

				}).catch(function(error) {
					console.log(error);
				});
			},
			//删除
			delAll() {
             //let SESSION_ID = JSON.parse(window.sessionStorage.getItem('SESSION_ID'));
			  var SESSION_ID=JSON.parse(window.localStorage.getItem('sessiond'))
				let _this = this
				let obj = {
					//请求的参数
					id: _this.id,
					userid: SESSION_ID.user.id,
				};

				let qs = require('qs');
			this.$axios.post("/yujia/user/delAddressByUser ", qs.stringify(obj), {
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}
					//重写headers 请求头  qs.stringify(json对象) 把对象转化为字符串
				}).then((response) => {
                 if(response.data.code =='1'){
					//    var btnArray = ['否', '是']
					//    mui.confirm('是否删除地址，确认？', '', btnArray, function(e) {
					// 	   if(e.index == 1){
							    mui.alert("删除成功")
								_this.$router.push({
									path: '/select_address',
										query: {}

						// 		})
						//    }else{
						// 	   console.log(2)
						//    }
					   })
					 
					//  alert("删除成功")
					//  this.$router.push({
					// 		path: '/select_address',
					// 		query: {}

					// 	})
                 }
                 

				}).catch(function(error) {
					console.log(error);
				});
			}

		},

	}
</script>

<style scoped>
	@import "../../assets/css/edit_address.css";
	.bug {
		color: #c9c9c9;
		border: 1px solid #d3d3d3;
	}
	
	.active {
		background: #5d50ab;
		color: #fff;
		border: none;
	}
</style>
